﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>项目查询</title>
    <link href="~/Scripts/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js"></script>
    <script src="~/Content/js/module_cols_defined.js"></script>
    <script src="~/Content/js/appendhandle.js"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />
    <link href="~/Content/formstyles.css" rel="stylesheet" />
    <script type="text/javascript">
        var pk = "ProjectNo";//不隐藏的主键
        var module_dialog = "#module_dialog";
        //var flag = "PMIndex";//页面标签
        var currentUserId = window.parent.RealName || "test_admin";//当前用户

        var currentpagedata = {
        }
        var view = getQueryVariable("view") || "PMMaintain";
        var ProjectNo = getQueryVariable("ProjectNo") || "";//传入的查询单据号
        var lock = false;//全局操作锁
        $(function () {
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "PMList", "KeyName": "PMList" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) {
                        //前端添加按钮 <a href="javascript:void(0)" class="easyui-linkbutton" onclick="columnDefined(currentUserId,initColumnMap,pk,flag)">列表自定义</a>
                        //data.toolbar.push({ "text": "导出", "id": "export", "iconCls": "icon-link", "handler": "linkOper();" })
                        // data.toolbar.push({ "text": "项目管理", "id": "btGantt", "iconCls": "icon-link", "handler": "pmNodeMgr();" })
                        //data.toolbar.push({ "text": "横道图", "id": "btGantt", "iconCls": "icon-link", "handler": "pmGantt();" })
                        //data.toolbar.push({ "text": "成本管理", "id": "btCostMgr", "iconCls": "icon-link", "handler": "costMgr();" })
                        //  data.toolbar.push('-',{ "text": "列自定义", "id": "btColSet", "iconCls": "icon-link", "handler": "columnDefined($('#ui_pm_dg'),currentUserId,pk,flag);" })
                        data.toolbar.push({ "text": "项目管理", "id": "btMgr", "iconCls": "icon-link", "handler": "pmNodeMgr();" })
                        data.toolbar.push({ "text": "项目设计", "id": "btn_DN", "iconCls": "icon-link", "handler": " pmDNMgr(1);" })
                        //data.toolbar.push({ "text": "项目设计", "id": "btn_DN", }) 
                        var toolbar = getToolBar(data);      //common.js
                        if (data.search) {     //判断是否有浏览权限
                            $("#ui_pm_dg").datagrid({       //初始化datagrid
                                url: "/Project/GetPMList?&r=" + Math.random(),
                                striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                                idField: 'ProjectID',
                                sort: 'UpdateTime',
                                order: 'desc',
                                pageList: [20, 40, 60, 80, 100],
                                queryParams: {
                                    "view": view,
                                    "ProjectNo": ProjectNo,
                                },
                                frozenColumns: [[
                                               {
                                                   hidden: true,
                                                   title: 'ID',
                                                   field: 'ProjectID'
                                               },
                                                 {
                                                     width: '100',
                                                     title: '项目编码',
                                                     field: 'ProjectNo',
                                                     formatter: function (value, row, index) {
                                                         return value.length > 8 ? '<span title="' + value + '">' + value + '</span>' : value;
                                                     }
                                                 },
                                                 {
                                                     //width: '120',
                                                     title: '项目名称',
                                                     field: 'ProjectName',
                                                     formatter: function (value, row, index) {
                                                         return value.length > 8 ? '<span title="' + value + '">' + value + '</span>' : value;
                                                     }
                                                 }

                                ]],
                                columns: [[
                                     {
                                         field: 'status', title: '状态', sortable: false, width: 45,
                                         formatter: function (value, row, index) {
                                             var x;
                                             switch (value) {
                                                 case 0:
                                                     x = "待确认";
                                                     break;
                                                 case 1:
                                                     x = "已确认";
                                                     break;
                                                 case 2:
                                                     x = "已下达";
                                                     break;
                                                 case 3:
                                                     x = "已结项";
                                                     break;
                                                 case 5:
                                                     x = "已终止";
                                                     break;
                                                 default:
                                                     x = value;
                                                     break;
                                             }
                                             return x;
                                             //return value == 1 ? '<img src="../../Content/themes/icon/chk_checked.gif" alt="已确认" title="项目已确认" />' : '<img src="../../Content/themes/icon/chk_unchecked.gif" alt="未确认" title="项目未确认" />';
                                         }
                                     },
                                 {
                                     field: 'Department', title: '部门', sortable: false, hidden: false, formatter: function (value, row, index) {
                                         if (value) { return value.substring(0, 4); }
                                     }
                                 },
                                {
                                    field: 'ProjectClerk', title: '业务员', sortable: false,
                                    hidden: false
                                },
                                {
                                    field: 'ProjectManager', title: '管理员', sortable: false,
                                    //width: 60
                                },{
                                    field: 'FNumber', title: '物料代码', sortable: false,
                                    hidden: true
                                },{ field: 'UpdateBy', title: '更新人', width: 60 },
                                  { field: 'UpdateTime', title: '更新时间', sortable: true, width: 70, formatter: getDate },
                                  {
                                      field: 'Remark', title: '项目描述', width: 500,
                                      formatter: function (value, row, index) {
                                          return value.length > 20 ? '<span title="' + value + '">' + value + '</span>' : value;
                                      }
                                  },
                                  { field: 'CreateBy', title: '创建人', width: 60, hidden: true },
                                  { field: 'CreateTime', title: '创建时间', sortable: true, width: 70, formatter: getDate, hidden: true },

                                ]],
                                toolbar: toolbar.length == 0 ? null : toolbar,
                                onSelect: function (rowIndex, rowData) {
                                    //   menuControl();
                                },
                                onLoadSuccess: function (data) {
                                    //loadColumnDefined($("#ui_pm_dg"), currentUserId, pk, flag);//列自定义 
                                    //修改menubutton
                                    //$('#btn_DN').menubutton({
                                    //    iconCls: 'icon-edit',
                                    //    menu: '#mm'
                                    //});
                                }
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })
      
            //回车搜索
            $("#ui_pm_search").find('input').on('keyup', function (event) {
                if (event.keyCode == '13') {
                    ui_pm_searchdata();
                }
            })
        });
        //菜单标灰处理函数
        function menuControl() {
            var rows = $("#ui_pm_dg").datagrid("getChecked");
            switch (rows[0].status) {
                case "":
                case 0:
                    $("#delete").linkbutton("enable");//允许删除
                    $("#confirm").linkbutton("enable");
                    $("#unconfirm").linkbutton("disable");
                    $("#assign").linkbutton("disable");
                    $("#unassign").linkbutton("disable");
                    break;
                case 1:
                    $("#delete").linkbutton("disable");//禁止删除
                    $("#confirm").linkbutton("disable");
                    $("#unconfirm").linkbutton("enable");
                    $("#assign").linkbutton("enable");
                    $("#unassign").linkbutton("disable");
                    break;
                case 2:
                    $("#delete").linkbutton("disable");//禁止删除
                    $("#confirm").linkbutton("disable");
                    $("#unconfirm").linkbutton("disable");
                    $("#assign").linkbutton("disable");
                    $("#unassign").linkbutton("enable");
                    break;
                case 3:
                    $("#delete").linkbutton("disable");//禁止删除
                    break;
                default:
                    $("#delete").linkbutton("disable");//禁止删除
                    break;
            }

        }
        //显示/隐藏 toolbar按钮
        function easyRightDisplay() {
            //获取所有的toolbar按钮
            var button = $('div.datagrid div.datagrid-toolbar a');
            for (var i = 0; i < button.length; i++) {
                var toolbar = button[i];
                var id = toolbar.id;
                if (id == "add") {  //隐藏Id为add的按钮
                    $('div.datagrid div.datagrid-toolbar a').eq(i).hide();
                }
                if (id == "delete") {  //不隐藏id为delete的按钮
                    //button.eq(i).hide();
                }
                //如果按钮都没权限，隐藏了可直接隐藏toolbar
                //$('div.datagrid div.datagrid-toolbar').hide();
            }
        }
        //openTabFormat = function (subtitle, url, icon) {
        //    var action = '<a href="javascript:void(0)" onclick="window.parent.addTab(\'{0}\',\'{1}\')">查看</a>';
        //    var htmls = stringFormat(action, subtitle, url);
        //    // console.log(htmls);
        //    return htmls;
        //}

        //查看横道图
        function pmGantt() {

            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row == null) {
                $.show_alert("提示", "请先勾选项目");
                return;
            }
            if (row.length > 1) {
                $.show_alert("提示", "不支持批量处理项目");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            window.parent.addTab(row.ProjectName, '/Project/gantt_singleP?ProjectID=' + row.ProjectID);

        }

        //查看项目管理面板
        function pmNodeMgr() {
            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row == null) {
                $.show_alert("提示", "请先勾选项目");
                return;
            }
            if (row.length > 1) {
                $.show_alert("提示", "不支持批量处理项目");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $('#mgrbuttonsDialog').dialog({
                title: '项目维护功能选择',
                //width: 500,
                // height: 350,
                closed: false,
                cache: false,
                // href: 'get_content.php',
                modal: true
            });
        }


        //新增项目
        function AddPMList() {
            $("<div/>").dialog({
                id: "ui_pm_add_dialog",
                href: "/views/Project/PMModel.html",
                title: "新增项目",
                height: $(window).height(),
                width: $(window).width(),
                modal: true,
                toolbar: [{
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function () {
                        if (lock) { return; } else { lock = true; }
                        $.ajax({     //提交数据保存
                            url: "/Project/AddNewProject?r=" + Math.random(),
                            type: "post",
                            data: {
                                "KeyCode": "CreatePMBill",
                                "ProjectID": $("#ProjectID").val(),
                                "ProjectNo": $("#ProjectNo").val(),
                                "ProjectName": $("#ProjectName").val(),
                                "ProjectManager": $("#ProjectManager").val(),
                                "ProjectClerk": $("#ProjectClerk").val(),
                                "Remark": $("#Remark").val(),
                                "Department": $("#comDepartmentList").val(),
                                "FNumber": $('#mainItemCode').combobox("getText"),
                            },
                            dataType: "json",
                            timeout: 5000,
                            success: function (data) {
                                lock = false;
                                if (data.success) {
                                    $.show_alert("成功", "保存成功！");
                                    $("#ui_pm_add_dialog").dialog('destroy');
                                    $("#ui_pm_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                                } else {
                                    $.show_alert("提示", data.msg);
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                if (textStatus == "timeout") {
                                    $.show_alert("提示", "请求超时，请刷新当前页重试！");
                                }
                                else {
                                    $.show_alert("错误", textStatus + "：" + errorThrown);
                                }
                            }
                        })

                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-cross',
                    handler: function () { $("#ui_pm_add_dialog").dialog('destroy'); }
                }],
                onLoad: function () {
                    $("#ProjectNo").textbox('enable');
                    $("#ProjectName").textbox('enable');
                    $("#ProjectManager").textbox('enable');
                    $("#ProjectClerk").textbox('enable');
                    $("#Remark").textbox('enable');
                    $("#comDepartmentList").combobox('enable');

                    $('#mainItemCode').combobox({
                        mode: 'remote',  //模式： 远程获取数据
                        url: '/Common/AutoComplete_ItemCode',  //远程数据请求地址
                        valueField: 'FName', 　　//value对应的属性字段
                        textField: 'FNumber',　　　 //text对应的属性字段
                        formatter: function (row) {
                            var opts = $(this).combobox('options');
                            return row[opts.textField] + " " + row[opts.valueField];
                        },
                        onChange: function (newValue, oldValue) {
                            //  $("#mainItemName").textbox('setValue', newValue);
                        }
                    });
                    //$("#CreateBy").attr('hidden', 'hidden');
                    //$("#CreateTime").attr('hidden', 'hidden');
                    //$("#UpdateTime").attr('hidden', 'hidden');
                    //$("#UpdateBy").attr('hidden', 'hidden');
                    //$("#tt").attr('hidden', 'hidden');//隐藏节点管理
                },
                onClose: function () {
                    $("#ui_pm_add_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }


        //项目管理角色授权：用于成本查看权限的管控
        function RoleAuthorize() {
            $("<div/>").dialog({
                id: "ui_pm_dg_role_authorize_dialog",
                href: "/Project/ProjectRoleAuthorize",
                title: "角色授权：",
                height: 280,
                width: 420,
                modal: true,
                buttons: [{
                    id: "ui_pm_setrole_btn",
                    text: '确 定',
                    handler: function () {
                        $("#SetPmRoleForm").form("submit", {
                            url: "/PMCost/SetRoleField",
                            onSubmit: function (param) {
                                $('#ui_pm_setrole_btn').linkbutton('disable');
                                param.fieldName = $("#fieldName").combobox('getValue');
                                param.RoleIDs = $("#comboxrole").combobox('getValues');
                            },
                            success: function (data) {
                                var dataJson = eval('(' + data + ')');
                                if (dataJson.success) {
                                    $("#ui_pm_dg_role_authorize_dialog").dialog('destroy');
                                    $.show_alert("提示", dataJson.msg);
                                    // $("#ui_user_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                } else {
                                    $('#ui_pm_setrole_btn').linkbutton('enable');
                                    $.show_alert("提示", dataJson.msg);
                                }
                            }
                        });
                    }
                }],
                onLoad: function () {
                    //如果是设置一个用户就自动勾选已经有的角色
                    //if (row.length == 1) {
                    //    $('#comboxrole').combobox('setValues', stringToList(row[0].UserRoleId));
                    //    $("#hiduserid").val(row[0].ID);
                    //    $("#txtusernameR").val(row[0].AccountName);
                    //}
                    //else {
                    //    var userids = "";
                    //    var usernames = "";
                    //    for (var i = 0; i < row.length; i++) {
                    //        userids += row[i].ID + ",";
                    //        usernames += row[i].AccountName + ",";
                    //    }
                    //    $("#hiduserid").val(userids.substring(0, userids.length - 1));
                    //    $("#txtusernameR").val(usernames.substring(0, usernames.length - 1));
                    //}
                },
                onClose: function () {
                    $("#ui_pm_dg_role_authorize_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }


        //从前端导出,只能用模拟表单
        // 直接通过ajax请求文件数据，jquery下载文件时不能触发浏览器弹出保存文件对话框！ 可以在javascript中访问下载的文件数据
        // 模拟表单提交同步方式下载文件
        // 能够弹出保存文件对话框
        function PMIndexExport() {
            //console.log("ajaxDownloadSynchronized");
            var rows = $("#ui_pm_dg").datagrid("getRows");
            for (var i = 0; i < rows.length; i++) {    //进行数据处理
                switch (rows[i].status) {
                    case 0:
                        rows[i].status = "待确认";
                        break;
                    case 1:
                        rows[i].status = "已确认";
                        break;
                    case 2:
                        rows[i].status = "已下达";
                        break;
                    case 3:
                        rows[i].status = "已结项";
                        break;
                    case 5:
                        rows[i].status = "已终止";
                        break;
                    default:
                        break;
                }
                //移除不要的字段
                delete rows[i].ProjectID;
                //delete rows[i].SaleOrderId;
                //delete rows[i].SaleOrderItems;
                //delete rows[i].SaleStatus;
                //delete rows[i].UserName;
                //delete rows[i].Customer;
                //delete rows[i].AddDate;
            }
            var bodyData = JSON.stringify(rows);  //转成json字符串
            //替换中文标题
            var a = bodyData.replace(/ProjectNo/g, "项目编码").replace(/ProjectName/g, "项目名称").replace(/status/g, "状态")
            .replace(/ProjectClerk/g, "业务员").replace(/ProjectManager/g, "管理员").replace(/EstWorkTime/g, "预估工时").replace(/UpdateBy/g, '最后更新人')
            .replace(/UpdateTime/g, "最后更新时间").replace(/Remark/g, "项目描述").replace(/CreateBy/g, "创建人").replace(/CreateTime/g, "创建时间");
            //var postData = {
            //    data: bodyData
            //};

            var url = "/Project/ExportExcel";
            var fileName = "testAjaxDownload.xls";
            var form = $("<form></form>").attr("action", url).attr("method", "post");
            form.append($("<input></input>").attr("type", "hidden").attr("name", "bodyData").attr("value", a));
            form.appendTo('body').submit().remove();
        }

        //从前端导出
        function exportPMList() {
            var rows = $("#ui_pm_dg").datagrid("getRows");


            //for (var i = 0; i < rows.length; i++) {    //进行数据处理
            //if (isArray(rows[i].OrganizedId)) {
            //    rows[i].OrganizedId = rows[i].OrganizedId[0];
            //}
            //if (isArray(rows[i].CustomerId)) {
            //    rows[i].CustomerId = rows[i].CustomerId[0];
            //}
            //if (rows[i].AdvanceDate != null) {
            //    var unix = rows[i].AdvanceDate.replace("/Date(", "").replace(")/", "");
            //    var un = unix.substring(0, 10);
            //    var newDate = new Date();
            //    newDate.setTime(un * 1000);

            //    rows[i].AdvanceDate = newDate.toLocaleString();
            //}
            //if (rows[i].OrderDate != null) {
            //    var unix = rows[i].OrderDate.replace("/Date(", "").replace(")/", "");
            //    var un = unix.substring(0, 10);
            //    var newDate = new Date();
            //    newDate.setTime(un * 1000);

            //    rows[i].OrderDate = newDate.toLocaleString();
            //}
            //if (rows[i].RetainageDate != null) {
            //    var unix = rows[i].RetainageDate.replace("/Date(", "").replace(")/", "");
            //    var un = unix.substring(0, 10);
            //    var newDate = new Date();
            //    newDate.setTime(un * 1000);

            //    rows[i].RetainageDate = newDate.toLocaleString();
            //}

            ////移除不要的字段
            //delete rows[i].SaleAtts;
            //delete rows[i].SaleOrderId;
            //delete rows[i].SaleOrderItems;
            //delete rows[i].SaleStatus;
            //delete rows[i].UserName;
            //delete rows[i].Customer;
            //delete rows[i].AddDate;

            //}
            var bodyData = JSON.stringify(rows);  //转成json字符串

            //替换中文标题
            // var a = bodyData.replace(/SaleOrderNo/g, "订单编号").replace(/OrderType/g, "订单类型").replace(/FromWhere/g, "订单来源")
            //.replace(/OrganizedId/g, "机构").replace(/SaleUser/g, "销售员").replace(/SaleTc/g, "销售提成").replace(/OrderDate/g, '订单日期')
            //.replace(/ContractNo/g, "合同编号").replace(/Amount/g, "总额").replace(/Advance/g, "首付款").replace(/AdvanceDate/g, "首付款日期")
            //.replace(/PayMethod/g, "支付方式").replace(/Retainage/g, "尾款").replace(/RetainageDate/g, "尾款日期").replace(/InlayPrice/g, "镶嵌款")
            //.replace(/CustManager/g, "客户经理").replace(/EquityNo/g, "认股书编号").replace(/LogisticsTotal/g, "物流费用")
            //.replace(/Remarks/g, "备注").replace(/CompletedStatus/g, "状态").replace(/CustomerId/g, "终端客户");

            var postData = {
                data: bodyData
            };


        }
        //修改项目
        function EditPMList() {
            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row == null) {
                $.show_alert("提示", "请先勾选要更新的项目");
                return;
            }
            if (row.length > 1) {
                $.show_alert("提示", "不支持批量修改项目");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $("<div/>").dialog({
                id: "ui_pm_edit_dialog",
                href: "/views/Project/PMModel.html",
                title: "更新项目",
                height: $(window).height(),
                width: $(window).width(),
                modal: true,
                toolbar: [{
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function () {
                        if (lock) { return; } else { lock = true; }
                        $.ajax({     //提交数据保存
                            url: "/Project/EditBasicProject?r=" + Math.random(),
                            type: "post",
                            data: {
                                "KeyCode": "EditPMBill",
                                "ProjectID": $("#ProjectID").val(),
                                "ProjectNo": $("#ProjectNo").val(),
                                "ProjectName": $("#ProjectName").val(),
                                "ProjectManager": $("#ProjectManager").val(),
                                "ProjectClerk": $("#ProjectClerk").val(),
                                "Department": $("#comDepartmentList").val(),
                                "FNumber": $('#mainItemCode').combobox("getText"),
                                "Remark": $("#Remark").val()
                            },
                            dataType: "json",
                            timeout: 5000,
                            success: function (data) {
                                lock = false;
                                if (data.success) {
                                    $.show_alert("成功", "保存成功！");
                                    $("#ui_pm_edit_dialog").dialog('destroy');
                                    $("#ui_pm_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                                } else {
                                    $.show_alert("提示", data.msg);
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                if (textStatus == "timeout") {
                                    $.show_alert("提示", "请求超时，请刷新当前页重试！");
                                }
                                else {
                                    $.show_alert("错误", textStatus + "：" + errorThrown);
                                }
                            }
                        })
                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-cross',
                    handler: function () { $("#ui_pm_edit_dialog").dialog('destroy'); }
                }],
                onLoad: function () {
                    $("#ProjectID").val(row.ProjectID);
                    $("#ProjectNo").textbox('setValue', row.ProjectNo);
                    $("#ProjectName").textbox('setValue', row.ProjectName);
                    $("#ProjectManager").textbox('setValue', row.ProjectManager);
                    $("#ProjectClerk").textbox('setValue', row.ProjectClerk);
                    $("#comDepartmentList").combobox('setValue', row.Department);
                    $("#CreateBy").textbox('setValue', row.CreateBy);
                    $("#CreateTime").textbox('setValue', row.CreateTime);
                    $("#UpdateTime").textbox('setValue', row.UpdateTime);
                    $("#UpdateBy").textbox('setValue', row.UpdateBy);

                    $("#Remark").textbox('setValue', row.Remark);
                    $("#ProjectNo").textbox('readonly', false);
                    $("#ProjectName").textbox('readonly', false);
                    $("#ProjectManager").textbox('readonly', false);
                    $("#ProjectClerk").textbox('readonly', false);
                    $("#Remark").textbox('readonly', false);
                    $("#comDepartmentList").combobox('readonly', false);
                    $('#mainItemCode').combobox({
                        mode: 'remote',  //模式： 远程获取数据
                        url: '/Common/AutoComplete_ItemCode',  //远程数据请求地址
                        valueField: 'FName', 　　//value对应的属性字段
                        textField: 'FNumber',　　　 //text对应的属性字段
                        formatter: function (row) {
                            var opts = $(this).combobox('options');
                            return row[opts.textField] + " " + row[opts.valueField];
                        },
                        onChange: function (newValue, oldValue) {
                            // $("#mainItemName").textbox('setValue', newValue);
                        }
                    });
                    $('#mainItemCode').combobox("setText", row.FNumber);
                },
                onClose: function () {
                    $("#ui_pm_edit_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }
        //删除项目
        function DelPMList() {
            var rows = $("#ui_pm_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要删除的项目");
                return;
            }
            if (rows.length > 1) {
                $.show_alert("提示", "不支持批量删除");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $.messager.confirm('提示', '确定删除：' + rows[0].ProjectName + '？', function (r) {
                if (r) {
                    $.ajax({
                        url: "/Project/DelProjectByID?r=" + Math.random(),
                        data: {
                            ID: rows[0].ProjectID
                        },
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", data.msg);
                                $("#ui_pm_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                ////如果“用户管理”标签页处于打开状态需要刷新，否则被删除的角色还显示，再点编辑用户就出错
                                //if ($('#tabs').tabs('exists', '用户管理')) {
                                //    $('#tabs').tabs('getTab', '用户管理').panel('refresh');
                                //}

                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }
        //查看项目详情
        function DetailPMList() {
            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row == null) {
                $.show_alert("提示", "请先勾选项目");
                return;
            }
            if (row.length > 1) {
                $.show_alert("提示", "不支持批量处理");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $("<div/>").dialog({
                id: "ui_pm_detail_dialog",
                href: "/Project/PMModelDetail",
                title: "查看项目",
                height: $(window).height(),
                width: $(window).width(),
                modal: true,
                toolbar: [{
                    text: '关闭',
                    iconCls: 'icon-cross',
                    handler: function () { $("#ui_pm_detail_dialog").dialog('destroy'); }
                }],
                onLoad: function () {
                    $("#ProjectID").val(row.ProjectID);
                    $("#ProjectNo").textbox('setValue', row.ProjectNo);
                    $("#ProjectName").textbox('setValue', row.ProjectName);
                    $("#ProjectManager").textbox('setValue', row.ProjectManager);
                    $("#ProjectClerk").textbox('setValue', row.ProjectClerk);
                    $("#comDepartmentList").combobox('setValue', row.Department);
                    $("#Remark").textbox('setValue', row.Remark);

                    $("#CreateBy").textbox('setValue', row.CreateBy);
                    $("#CreateTime").textbox('setValue', row.CreateTime);
                    $("#UpdateTime").textbox('setValue', row.UpdateTime);
                    $("#UpdateBy").textbox('setValue', row.UpdateBy);
                },
                onClose: function () {
                    $("#ui_pm_detail_dialog").dialog('destroy');  //销毁dialog对象
                }
            });


        }


        //项目状态：确认
        function confirmPMIndex() {
            var rows = $("#ui_pm_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要确认的项目");
                return;
            }
            if (rows.length > 1) {
                $.show_alert("提示", "不支持批量处理");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $.messager.confirm('提示', '确认该项目：' + rows[0].ProjectName + '？', function (r) {
                if (r) {
                    $.ajax({
                        url: "/Project/confirmProjectByID?r=" + Math.random(),
                        data: {
                            ID: rows[0].ProjectID,
                            confirm: "confirm"
                        },
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", data.msg);
                                $("#ui_pm_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                ////如果“用户管理”标签页处于打开状态需要刷新，否则被删除的角色还显示，再点编辑用户就出错
                                //if ($('#tabs').tabs('exists', '用户管理')) {
                                //    $('#tabs').tabs('getTab', '用户管理').panel('refresh');
                                //}

                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }
        //取消确认项目
        function unconfirmPMIndex() {
            var rows = $("#ui_pm_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要取消确认的项目");
                return;
            }
            if (rows.length > 1) {
                $.show_alert("提示", "不支持批量处理");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $.messager.confirm('提示', '取消确认该项目：' + rows[0].ProjectName + '？', function (r) {
                if (r) {
                    $.ajax({
                        url: "/Project/confirmProjectByID?r=" + Math.random(),
                        data: {
                            ID: rows[0].ProjectID,
                            confirm: "unconfirm"
                        },
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", data.msg);
                                $("#ui_pm_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                ////如果“用户管理”标签页处于打开状态需要刷新，否则被删除的角色还显示，再点编辑用户就出错
                                //if ($('#tabs').tabs('exists', '用户管理')) {
                                //    $('#tabs').tabs('getTab', '用户管理').panel('refresh');
                                //}

                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }
        //下达任务
        function assignPMIndex() {
            var rows = $("#ui_pm_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要下达的项目");
                return;
            }
            if (rows.length > 1) {
                $.show_alert("提示", "不支持批量处理");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $.messager.confirm('提示', '下达该项目：' + rows[0].ProjectName + '？', function (r) {
                if (r) {
                    $.ajax({
                        url: "/Project/confirmProjectByID?r=" + Math.random(),
                        data: {
                            ID: rows[0].ProjectID,
                            confirm: "2"//1，已确认；2,已下达
                        },
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", data.msg);
                                $("#ui_pm_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                ////如果“用户管理”标签页处于打开状态需要刷新，否则被删除的角色还显示，再点编辑用户就出错
                                //if ($('#tabs').tabs('exists', '用户管理')) {
                                //    $('#tabs').tabs('getTab', '用户管理').panel('refresh');
                                //}

                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }
        //取消下达任务状态
        function unassignPMIndex() {
            var rows = $("#ui_pm_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要取消下达的项目");
                return;
            }
            if (rows.length > 1) {
                $.show_alert("提示", "不支持批量处理");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $.messager.confirm('提示', '取消下达该项目：' + rows[0].ProjectName + '？', function (r) {
                if (r) {
                    $.ajax({
                        url: "/Project/confirmProjectByID?r=" + Math.random(),
                        data: {
                            ID: rows[0].ProjectID,
                            confirm: "1" //改为已确认
                        },
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", data.msg);
                                $("#ui_pm_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                ////如果“用户管理”标签页处于打开状态需要刷新，否则被删除的角色还显示，再点编辑用户就出错
                                //if ($('#tabs').tabs('exists', '用户管理')) {
                                //    $('#tabs').tabs('getTab', '用户管理').panel('refresh');
                                //}

                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }
        function ui_pm_searchdata() {
            $("#ui_pm_dg").datagrid('load', {
                ProjectNo: $('#txtProjectNo').val(),
                ProjectName: $('#txtPMName').val(),
                status: $('#FStatus').val(),
                CreateTimeS: $('#txtAddBeginDate').datetimebox('getValue'),
                CreateTimeE: $('#txtAddEndDate').datetimebox('getValue')
            });
            // $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
        }

        function ui_pm_cleardata() {
            $('#ui_pm_search input').val('');
            $('#ui_pm_search select').val('select');
            $('#txtAddBeginDate').datetimebox('setValue', '');
            $('#txtAddEndDate').datetimebox('setValue', '');
            $("#ui_pm_dg").datagrid('load', {});//清空条件自动加载数据

            //  $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
        }



        //商务管理
        function pmBSMgr(edit) {
            //edit=1,支持编辑；edit=0，不可编辑
            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row == null) {
                $.show_alert("提示", "请先勾选项目");
                return;
            }
            if (row.length > 1) {
                $.show_alert("提示", "不支持批量处理项目");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }

            $("<div/>").dialog({
                id: "ui_pm_bs_dialog",
                href: "/Project/PMBSMgrEntry",
                title: "项目商务",
                height: $(window).height(),
                width: $(window).width(),
                closed: false,
                modal: true,
                toolbar: [{
                    text: '保存',
                    id: 'bs_save_bt',
                    iconCls: 'icon-save',
                    handler: function () {
                        if (lock) { return; } else { lock = true; }
                        $.ajax({     //提交数据保存
                            url: "/Project/EditPMNode?r=" + Math.random(),
                            type: "post",
                            data: {
                                "ProjectID": row.ProjectID,
                                "NodeID": 2,
                                "PSTime": $("#bsPSTime").datebox('getValue'),
                                "PETime": $("#bsPETime").datebox('getValue'),
                                "RSTime": $("#bsRSTime").datebox('getValue'),
                                "RETime": $("#bsRETime").datebox('getValue'),
                                "Remark": $("#bsRemark").val(),
                                "Executor": $("#bsExecutor").val(),
                            },
                            dataType: "json",
                            timeout: 5000,
                            success: function (data) {
                                lock = false;
                                if (data.success) {
                                    $.show_alert("成功", "保存成功！");
                                    //$("#ui_pm_bs_dialog").dialog('destroy');
                                    //$("#ui_pm_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                                } else {
                                    $.show_alert("提示", data.msg);
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                if (textStatus == "timeout") {
                                    $.show_alert("提示", "请求超时，请刷新当前页重试！");
                                }
                                else {
                                    $.show_alert("错误", textStatus + "：" + errorThrown);
                                }
                            }
                        })

                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-cross',
                    handler: function () {
                        $("#ui_pm_bs_dialog").dialog('destroy');
                    }
                }],
                onLoad: function () {
                    //$("#ProjectID").textbox('setValue', row.ProjectID);
                    $("#ProjectNo").textbox('setValue', row.ProjectNo);
                    $("#ProjectName").textbox('setValue', row.ProjectName);
                    $("#ProjectManager").textbox('setValue', row.ProjectManager);
                    $("#ProjectClerk").textbox('setValue', row.ProjectClerk);
                    $("#comDepartmentList").combobox('setValue', row.Department);
                    //获取并绑定已有的节点信息
                    $.getJSON("/Project/GetPMNodeInfo", { ProjectID: row.ProjectID, NodeID: 2 }, function (data) {
                        if (data.success) {
                            nodedata = data.rows[0];
                            $("#bsExecutor").textbox('setValue', nodedata.executor || "");
                            $("#bsPSTime").datebox('setValue', nodedata.PSTime.replace(/\//g, '-'));//将全局的\号替换为-，使得js能识别为日期格式
                            $("#bsPETime").datebox('setValue', nodedata.PETime.replace(/\//g, '-'));
                            $("#bsRSTime").datebox('setValue', nodedata.RSTime.replace(/\//g, '-'));
                            $("#bsRETime").datebox('setValue', nodedata.RETime.replace(/\//g, '-'));
                            $("#bsRemark").textbox('setValue', nodedata.Remark);
                            //加载附件,nodedata.AppendListID
                            var aid = nodedata.AppendListID;
                            $('#bsdatagrid').datagrid({
                                url: "/Project/GetAppendList?AppendListID=" + aid + "&r=" + Math.random(),
                                toolbar: [{
                                    text: '添加',
                                    id: 'append_add_bt',
                                    iconCls: 'icon-add',
                                    handler: function () {
                                        uploadfile(aid, $("#bsdatagrid"));
                                    }
                                }, {
                                    text: '删除',
                                    id: 'append_del_bt',
                                    iconCls: 'icon-delete',
                                    handler: function () {
                                        Delfile($("#bsdatagrid"));
                                    }
                                }, {
                                    text: '下载附件',
                                    iconCls: 'icon-save',
                                    handler: function () {
                                        downloadfile($("#bsdatagrid"));
                                    }
                                }]
                            });

                        } else {
                            $.show_alert("提示", data.msg);
                        }
                    });


                },
                onOpen: function () {
                    if (edit == 0) {
                        setTimeout(function () {
                            $("#bs_save_bt").remove();
                            $("#append_add_bt").remove();
                            $("#append_del_bt").remove();

                        }, 200);//不可编辑，仅查看处理，隐藏菜单
                    }
                },
                onClose: function () {
                    $("#ui_pm_bs_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }
        //现场施工管理
        function pmCNMgr(edit) {
            //edit=1,支持编辑；edit=0，不可编辑
            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row == null) {
                $.show_alert("提示", "请先勾选项目");
                return;
            }
            if (row.length > 1) {
                $.show_alert("提示", "不支持批量处理项目");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }

            $("<div/>").dialog({
                id: "ui_pm_bs_dialog",
                href: "/Project/PMCNMgrEntry",
                title: "现场施工",
                height: $(window).height(),
                width: $(window).width(),
                closed: false,
                modal: true,
                toolbar: [{
                    text: '保存',
                    id: 'bs_save_bt',
                    iconCls: 'icon-save',
                    handler: function () {
                        if (lock) { return; } else { lock = true; }
                        $.ajax({     //提交数据保存
                            url: "/Project/EditPMNode?r=" + Math.random(),
                            type: "post",
                            data: {
                                "ProjectID": row.ProjectID,
                                "NodeID": 6,//现场施工
                                "PSTime": $("#bsPSTime").datebox('getValue'),
                                "PETime": $("#bsPETime").datebox('getValue'),
                                "RSTime": $("#bsRSTime").datebox('getValue'),
                                "RETime": $("#bsRETime").datebox('getValue'),
                                "Remark": $("#bsRemark").val(),
                                "Executor": $("#bsExecutor").val(),
                            },
                            dataType: "json",
                            timeout: 5000,
                            success: function (data) {
                                lock = false;
                                if (data.success) {
                                    $.show_alert("成功", "保存成功！");
                                    //$("#ui_pm_bs_dialog").dialog('destroy');
                                    //$("#ui_pm_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                                } else {
                                    $.show_alert("提示", data.msg);
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                if (textStatus == "timeout") {
                                    $.show_alert("提示", "请求超时，请刷新当前页重试！");
                                }
                                else {
                                    $.show_alert("错误", textStatus + "：" + errorThrown);
                                }
                            }
                        })

                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-cross',
                    handler: function () {
                        $("#ui_pm_bs_dialog").dialog('destroy');
                    }
                }],
                onLoad: function () {
                    //$("#ProjectID").textbox('setValue', row.ProjectID);
                    $("#ProjectNo").textbox('setValue', row.ProjectNo);
                    $("#ProjectName").textbox('setValue', row.ProjectName);
                    $("#ProjectManager").textbox('setValue', row.ProjectManager);
                    $("#ProjectClerk").textbox('setValue', row.ProjectClerk);
                    $("#comDepartmentList").combobox('setValue', row.Department);
                    //获取并绑定已有的节点信息
                    $.getJSON("/Project/GetPMNodeInfo", { ProjectID: row.ProjectID, NodeID: 6 }, function (data) {
                        if (data.success) {
                            nodedata = data.rows[0];
                            $("#bsExecutor").textbox('setValue', nodedata.executor || "");
                            $("#bsPSTime").datebox('setValue', nodedata.PSTime.replace(/\//g, '-'));//将全局的\号替换为-，使得js能识别为日期格式
                            $("#bsPETime").datebox('setValue', nodedata.PETime.replace(/\//g, '-'));
                            $("#bsRSTime").datebox('setValue', nodedata.RSTime.replace(/\//g, '-'));
                            $("#bsRETime").datebox('setValue', nodedata.RETime.replace(/\//g, '-'));
                            $("#bsRemark").textbox('setValue', nodedata.Remark);
                            //加载附件,nodedata.AppendListID
                            var aid = nodedata.AppendListID;
                            $('#bsdatagrid').datagrid({
                                url: "/Project/GetAppendList?AppendListID=" + aid + "&r=" + Math.random(),
                                toolbar: [{
                                    text: '添加',
                                    id: 'append_add_bt',
                                    iconCls: 'icon-add',
                                    handler: function () {
                                        uploadfile(aid, $("#bsdatagrid"));
                                    }
                                }, {
                                    text: '删除',
                                    id: 'append_del_bt',
                                    iconCls: 'icon-delete',
                                    handler: function () {
                                        Delfile($("#bsdatagrid"));
                                    }
                                }, {
                                    text: '下载附件',
                                    iconCls: 'icon-save',
                                    handler: function () {
                                        downloadfile($("#bsdatagrid"));
                                    }
                                }]
                            });

                        } else {
                            $.show_alert("提示", data.msg);
                        }
                    });


                },
                onOpen: function () {
                    if (edit == 0) {
                        setTimeout(function () {
                            $("#bs_save_bt").remove();
                            $("#append_add_bt").remove();
                            $("#append_del_bt").remove();

                        }, 200);//不可编辑，仅查看处理，隐藏菜单
                    }
                },
                onClose: function () {
                    $("#ui_pm_bs_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }
        //生产制造管理
        function pmMEMgr(edit) {
            //edit=1,支持编辑；edit=0，不可编辑
            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row == null) {
                $.show_alert("提示", "请先勾选项目");
                return;
            }
            if (row.length > 1) {
                $.show_alert("提示", "不支持批量处理项目");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }

            $("<div/>").dialog({
                id: "ui_pm_bs_dialog",
                href: "/Project/PMMEMgrEntry",
                title: "生产制造",
                height: $(window).height(),
                width: $(window).width(),
                closed: false,
                modal: true,
                toolbar: [{
                    text: '保存',
                    id: 'bs_save_bt',
                    iconCls: 'icon-save',
                    handler: function () {
                        if (lock) { return; } else { lock = true; }
                        $.ajax({     //提交数据保存
                            url: "/Project/EditPMNode?r=" + Math.random(),
                            type: "post",
                            data: {
                                "ProjectID": row.ProjectID,
                                "NodeID": 5,
                                "PSTime": $("#mePSTime").datebox('getValue'),
                                "PETime": $("#mePETime").datebox('getValue'),
                                "RSTime": $("#meRSTime").datebox('getValue'),
                                "RETime": $("#meRETime").datebox('getValue'),
                                "Remark": $("#meRemark").val(),
                                "Executor": $("#meExecutor").val(),
                                "estworktime": $("#estWorkTime").val(),//预估工时
                                "weight1": $("#weight1").val(),//重量1
                                "weight2": $("#weight2").val(),//重量2
                                "workitem1": $("#workitem1").combogrid("getText"),//工时项目类别1
                                "workitem2": $("#workitem2").combogrid("getText"),//

                            },
                            dataType: "json",
                            timeout: 5000,
                            success: function (data) {
                                lock = false;
                                if (data.success) {
                                    $.show_alert("成功", "保存成功！");
                                    //$("#ui_pm_bs_dialog").dialog('destroy');
                                    //$("#ui_pm_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
                                } else {
                                    $.show_alert("提示", data.msg);
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                if (textStatus == "timeout") {
                                    $.show_alert("提示", "请求超时，请刷新当前页重试！");
                                }
                                else {
                                    $.show_alert("错误", textStatus + "：" + errorThrown);
                                }
                            }
                        })

                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-cross',
                    handler: function () {
                        $("#ui_pm_bs_dialog").dialog('destroy');
                    }
                }],
                onLoad: function () {
                    //$("#ProjectID").textbox('setValue', row.ProjectID);
                    $("#ProjectNo").textbox('setValue', row.ProjectNo);
                    $("#ProjectName").textbox('setValue', row.ProjectName);
                    $("#ProjectManager").textbox('setValue', row.ProjectManager);
                    $("#ProjectClerk").textbox('setValue', row.ProjectClerk);
                    $("#comDepartmentList").combobox('setValue', row.Department);
                    //获取并绑定已有的节点信息
                    $.getJSON("/Project/GetPMNodeInfo", { ProjectID: row.ProjectID, NodeID: 5 }, function (data) {
                        if (data.success) {
                            nodedata = data.rows[0];
                            $("#meExecutor").textbox('setValue', nodedata.executor);
                            $("#mePSTime").datebox('setValue', nodedata.PSTime.replace(/\//g, '-'));
                            $("#mePETime").datebox('setValue', nodedata.PETime.replace(/\//g, '-'));
                            $("#meRSTime").datebox('setValue', nodedata.RSTime.replace(/\//g, '-'));
                            $("#meRETime").datebox('setValue', nodedata.RETime.replace(/\//g, '-'));
                            $("#meRemark").textbox('setValue', nodedata.Remark);
                            $("#estWorkTime").textbox('setValue', nodedata.EstWorkTime);
                            $("#weight1").textbox('setValue', nodedata.weight1);
                            $("#weight2").textbox('setValue', nodedata.weight2);
                            $("#workitem1").val(nodedata.workitem1);//input 赋值
                            $("#workitem2").val(nodedata.workitem2);


                            //为工时类绑定下拉选择内容；
                            $("input[id^='workitem']").combogrid({//以workitem开头的id
                                delay: 500,
                                mode: 'remote',
                                panelWidth: 200,
                                //value: '请选择类别',
                                idField: 'itemNo',
                                textField: 'itemClass',
                                url: "/Project/GetWorkTimeClass?&r=", //+ Math.random(),//获取工时项目类json数据
                                columns: [[
                                //{ field: 'itemNo', title: 'ID', width: 20 },
                                { field: 'itemClass', title: '类别', width: 150 },
                                { field: 'Stime', title: '工时', width: 30 }
                                ]]
                            });
                            //为工时绑定自动计算功能
                            $("#estWorkTime").textbox({
                                buttonText: "计算工时",
                                buttonAlign: "right",
                                onClickButton: function () {
                                    var stime1 = 0, stime2 = 0;
                                    var g1 = $('#workitem1').combogrid('grid');
                                    var g2 = $('#workitem2').combogrid('grid');
                                    if (g1.datagrid('getSelected') == null)//未选择
                                    {
                                        //判断是否符合选项
                                        var text1 = $("#workitem1").combogrid("getText");
                                        var rows = g1.datagrid('getRows');
                                        for (var i = 0; i < rows.length; i++) {
                                            if (text1 == rows[i].itemClass) { stime1 = rows[i].Stime; break; }
                                        }
                                    } else {
                                        stime1 = g1.datagrid('getSelected').Stime;
                                    }
                                    if (g2.datagrid('getSelected') == null)//未选择
                                    {
                                        var text2 = $("#workitem2").combogrid("getText");
                                        var rows = g1.datagrid('getRows');
                                        for (var i = 0; i < rows.length; i++) {
                                            if (text2 == rows[i].itemClass) { stime2 = rows[i].Stime; break; }
                                        }
                                    } else {
                                        stime2 = g2.datagrid('getSelected').Stime;
                                    }
                                    try {
                                        var w1 = $("#weight1").val();
                                        var w2 = $("#weight2").val();
                                        var time = stime1 * w1 + stime2 * w2;
                                        $("#estWorkTime").textbox('setValue', time);
                                    } catch (e) {
                                        $.show_alert("提示", "工时项目类别输入格式有误,请重新输入！");
                                    }
                                }
                            });

                            //加载附件,nodedata.AppendListID
                            var aid = nodedata.AppendListID;
                            $('#medatagrid').datagrid({
                                url: "/Project/GetAppendList?AppendListID=" + aid + "&r=" + Math.random(),
                                toolbar: [{
                                    text: '添加',
                                    id: 'append_add_bt',
                                    iconCls: 'icon-add',
                                    handler: function () {
                                        uploadfile(aid, $("#medatagrid"));
                                    }
                                }, {
                                    text: '删除',
                                    id: 'append_del_bt',
                                    iconCls: 'icon-delete',
                                    handler: function () {
                                        Delfile($("#medatagrid"));
                                    }
                                }, {
                                    text: '下载附件',
                                    iconCls: 'icon-save',
                                    handler: function () {
                                        downloadfile($("#medatagrid"));
                                    }
                                }]
                            });
                        } else {
                            $.show_alert("提示", data.msg);
                        }
                    });
                },
                onOpen: function () {
                    if (edit == 0) {
                        setTimeout(function () {
                            $("#bs_save_bt").remove();
                            $("#append_add_bt").remove();
                            $("#append_del_bt").remove();

                        }, 200);//不可编辑，仅查看处理，隐藏菜单
                    }
                },
                onClose: function () {
                    $("#ui_pm_bs_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }
        //设计管理
        function pmDNMgr(edit) {
            //edit=1,支持编辑；edit=0，不可编辑
            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row == null) {
                $.show_alert("提示", "请先勾选项目");
                return;
            }
            if (row.length > 1) {
                $.show_alert("提示", "不支持批量处理项目");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }

            window.parent.addTab("项目设计", "/Views/Project/PMDNMgrEntry.html?r=" + Math.random()+"&ProjectID=" + row.ProjectID);

            //$("<div/>").dialog({
            //    id: "ui_pm_bs_dialog",
            //    href: "/Views/Project/PMDNMgrEntry.html",
            //    title: "项目设计",
            //    height: $(window).height(),
            //    width: $(window).width(),
            //    closed: false,
            //    modal: true,
            //    toolbar: [{
            //        text: '保存',
            //        id: 'bs_save_bt',
            //        iconCls: 'icon-save',
            //        handler: function () {
            //            if (lock) { return; } else { lock = true; }
            //            $.ajax({     //提交数据保存
            //                url: "/Project/EditPMNode?r=" + Math.random(),
            //                type: "post",
            //                data: {
            //                    "ProjectID": row.ProjectID,
            //                    "NodeID": 4,
            //                    "PSTime": $("#bsPSTime").datebox('getValue'),
            //                    "PETime": $("#bsPETime").datebox('getValue'),
            //                    "RSTime": $("#bsRSTime").datebox('getValue'),
            //                    "RETime": $("#bsRETime").datebox('getValue'),
            //                    "Remark": $("#bsRemark").val(),
            //                    "Executor": $("#bsExecutor").val(),
            //                },
            //                dataType: "json",
            //                timeout: 5000,
            //                success: function (data) {
            //                    lock = false;
            //                    if (data.success) {
            //                        $.show_alert("成功", "保存成功！");
            //                        //$("#ui_pm_bs_dialog").dialog('destroy');
            //                        //$("#ui_pm_dg").datagrid("reload");//.datagrid('clearSelections').datagrid('clearChecked');
            //                    } else {
            //                        $.show_alert("提示", data.msg);
            //                    }
            //                },
            //                error: function (XMLHttpRequest, textStatus, errorThrown) {
            //                    if (textStatus == "timeout") {
            //                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
            //                    }
            //                    else {
            //                        $.show_alert("错误", textStatus + "：" + errorThrown);
            //                    }
            //                }
            //            })

            //        }
            //    }, {
            //        text: '关闭',
            //        iconCls: 'icon-cross',
            //        handler: function () {
            //            $("#ui_pm_bs_dialog").dialog('destroy');
            //        }
            //    }],
            //    onLoad: function () {
            //        //$("#ProjectID").textbox('setValue', row.ProjectID);
            //        $("#ProjectNo").textbox('setValue', row.ProjectNo);
            //        $("#ProjectName").textbox('setValue', row.ProjectName);
            //        $("#ProjectManager").textbox('setValue', row.ProjectManager);
            //        $("#ProjectClerk").textbox('setValue', row.ProjectClerk);
            //        $("#comDepartmentList").combobox('setValue', row.Department);
            //        //获取并绑定已有的节点信息
            //        $.getJSON("/Project/GetPMNodeInfo", { ProjectID: row.ProjectID, NodeID: 4 }, function (data) {
            //            if (data.success) {
            //                nodedata = data.rows[0];
            //                $("#bsExecutor").textbox('setValue', nodedata.executor || "");
            //                $("#bsPSTime").datebox('setValue', nodedata.PSTime.replace(/\//g, '-'));//将全局的\号替换为-，使得js能识别为日期格式
            //                $("#bsPETime").datebox('setValue', nodedata.PETime.replace(/\//g, '-'));
            //                $("#bsRSTime").datebox('setValue', nodedata.RSTime.replace(/\//g, '-'));
            //                $("#bsRETime").datebox('setValue', nodedata.RETime.replace(/\//g, '-'));
            //                $("#bsRemark").textbox('setValue', nodedata.Remark);
            //                //加载附件,nodedata.AppendListID
            //                var aid = nodedata.AppendListID;
            //                $('#bsdatagrid').datagrid({
            //                    url: "/Project/GetAppendList?AppendListID=" + aid + "&r=" + Math.random(),
            //                    toolbar: [{
            //                        text: '添加',
            //                        id: 'append_add_bt',
            //                        iconCls: 'icon-add',
            //                        handler: function () {
            //                            uploadfile(aid, $("#bsdatagrid"));
            //                        }
            //                    }, {
            //                        text: '删除',
            //                        id: 'append_del_bt',
            //                        iconCls: 'icon-delete',
            //                        handler: function () {
            //                            Delfile($("#bsdatagrid"));
            //                        }
            //                    }, {
            //                        text: '下载附件',
            //                        iconCls: 'icon-save',
            //                        handler: function () {
            //                            downloadfile($("#bsdatagrid"));
            //                        }
            //                    }]
            //                });

            //            } else {
            //                $.show_alert("提示", data.msg);
            //            }
            //        });


            //    },
            //    onOpen: function () {
            //        if (edit == 0) {
            //            setTimeout(function () {
            //                $("#bs_save_bt").remove();
            //                $("#append_add_bt").remove();
            //                $("#append_del_bt").remove();

            //            }, 200);//不可编辑，仅查看处理，隐藏菜单
            //        }
            //    },
            //    onClose: function () {
            //        $("#ui_pm_bs_dialog").dialog('destroy');  //销毁dialog对象
            //    }
            //});
        }
        //成本管理功能模块
        function pmCostMgr() {
            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row == null) {
                $.show_alert("提示", "请先勾选项目");
                return;
            }
            if (row.length > 1) {
                $.show_alert("提示", "不支持批量处理项目");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $("<div/>").dialog({
                id: "ui_pm_cost_dialog",
                href: "/Project/PMCost",
                queryParams: {
                    ProjectID: row.ProjectID,
                    ProjectNo: row.ProjectNo,
                    ProjectName: row.ProjectName,
                    IcmoNo: row.IcmoNo,//关联主单号
                    FitemNo: row.FitemNo,//关联物料
                    FModel: row.FModel,//关联物料
                    FName: row.FName,//关联物料
                    estcost: row.estCost,//预估成本
                    budCost: row.budCost,//预算成本
                    stdCost: row.stdCost,//标准成本
                    reaCost: row.reaCost,//实际成本

                },

                title: "成本管理",
                height: $(window).height(),
                width: $(window).width(),
                modal: true,
                toolbar: [],
                onClose: function () {
                    $("#ui_pm_cost_dialog").dialog('destroy');  //销毁dialog对象
                    $("#ui_pm_dg").datagrid("reload");//刷新主表
                }
            })

        }


    </script>
</head>
<body>
    <div id="ui_pm_layout" class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'north',split:true,border:true,collapsed:true" title="条件搜索" style="height:104px;">
            <div id="ui_pm_search">
                <table class="tableForm" style="width: 99%; height: 100%; background: #F5F5F5;">
                    <tr>
                        <th>
                            项目编码：
                        </th>
                        <td>
                            <input name="txtProjectNo" id="txtProjectNo" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>

                        <th>
                            项目名称：
                        </th>
                        <td>
                            <input name="txtPMName" id="txtPMName" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>

                        <th>
                            项目状态：
                        </th>
                        <td>
                            <select name="FStatus" id="FStatus">
                                <option value="select">请选择</option>
                                <option value="0">未确认</option>
                                <option value="1">已确认</option>
                                <option value="2">已下达</option>
                                <option value="3">已完成</option>
                            </select>
                        </td>

                    <tr>
                        <th>
                            添加时间：
                        </th>
                        <td>
                            <input name="txtAddBeginDate" id="txtAddBeginDate" class="easyui-datetimebox"
                                   editable="false" style="width:150px;height:22px;" />
                        </td>

                        <th>
                            至：
                        </th>
                        <td>
                            <input name="txtAddEndDate" id="txtAddEndDate" class="easyui-datetimebox"
                                   editable="false" style="width:150px;height:22px;" />
                        </td>
                        <td colspan="4">
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                               onclick="ui_pm_searchdata();">搜索</a>
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                               onclick="ui_pm_cleardata();">清空条件</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div data-options="region:'center',border:false">
            <table id="ui_pm_dg" data-options="fit:true,border:false"></table>
        </div>
    </div>
    <div id="module_column_defined_dialog" buttons="#module_column_defined_dialog_button"></div>
    <div style="text-align:center" id="module_column_defined_dialog_button">
        <a href="javascript:void(0)" id="buttone-column-defined-save-select-all" class="easyui-linkbutton" iconcls="icon-edit-rf" onclick="selectAllColumn($('#ui_pm_dg'))">全选</a>
        <a href="javascript:void(0)" id="buttone-column-defined-save" class="easyui-linkbutton" iconcls="icon-ok-rf">确定</a>
        <a href="javascript:void(0)" id="button-column-defined-cancel" class="easyui-linkbutton" iconcls="icon-reload-rf" onclick="resetColumn($('#ui_pm_dg'),currentUserId,pk,flag)">重置</a>
    </div>

    <div id="mgrbuttonsDialog" class="easyui-dialog" style="width:500px;height:340px;"
         data-options="resizable:true,modal:true, closed: true,">
        请点击操作按钮：<hr>
        <div style="margin:20px">
            <a id="btnBS0" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-more',width:200" onclick="pmBSMgr(0)">查看合同管理</a>
            <a id="btnBS1" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',width:200" onclick="pmBSMgr(1)">管理商务合同</a><br><br>
            <a id="btnDN0" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-more',width:200" onclick="pmDNMgr(0)">查看项目设计</a>
            <a id="btnDN1" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',width:200" onclick="pmDNMgr(1)">管理项目设计</a><br><br>
            <a id="btnME0" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-more',width:200" onclick="pmMEMgr(0)">查看生产制造</a>
            <a id="btnME1" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',width:200" onclick="pmMEMgr(1)">管理生产制造</a><br><br>
            <a id="btnCN0" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-more',width:200" onclick="pmCNMgr(0)">查看现场施工</a>
            <a id="btnCN1" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',width:200" onclick="pmCNMgr(1)">管理现场施工</a><br><br>
            <a id="btnCost" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',width:200" onclick="pmCostMgr()">项目成本管理</a>
        </div>
    </div>
    <div id="mm" >
        <div data-options="iconCls:'icon-undo'">Undo</div>
        <div data-options="iconCls:'icon-redo'">Redo</div>
        <div class="menu-sep"></div>
        <div>Cut</div>
        <div>Copy</div>
        <div>Paste</div>
        <div class="menu-sep"></div>
        <div data-options="iconCls:'icon-remove'">Delete</div>
        <div>Select All</div>
    </div>
</body>
</html>